package com.lxmes.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.base.domain.JcItembzinfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcIteminfoDistri;
import com.lxmes.base.service.IJcIteminfoDistriService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 物料储分配送工艺基础表Controller
 * 
 * @author 张志煜
 * @date 2023-03-21
 */
@RestController
@RequestMapping("/base/iteminfoDistri")
public class JcIteminfoDistriController extends BaseController
{
    @Autowired
    private IJcIteminfoDistriService jcIteminfoDistriService;

    /**
     * 查询物料储分配送工艺基础表列表
     */
    @PreAuthorize("@ss.hasPermi('base:iteminfoDistri:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcIteminfoDistri jcIteminfoDistri)
    {
        startPage();
        List<JcIteminfoDistri> list = jcIteminfoDistriService.selectJcIteminfoDistriList(jcIteminfoDistri);
        return getDataTable(list);
    }

    /**
     * 导出物料储分配送工艺基础表列表
     */
    @PreAuthorize("@ss.hasPermi('base:iteminfoDistri:export')")
    @Log(title = "物料储分配送工艺基础表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcIteminfoDistri jcIteminfoDistri)
    {
        List<JcIteminfoDistri> list = jcIteminfoDistriService.selectJcIteminfoDistriList(jcIteminfoDistri);
        ExcelUtil<JcIteminfoDistri> util = new ExcelUtil<JcIteminfoDistri>(JcIteminfoDistri.class);
        util.exportExcel(response, list, "物料储分配送工艺基础表数据");
    }
    /**
     * 导入物料储分配送工艺基础表列表
     */
    @Log(title = "物料储分配送工艺基础表导入", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JcIteminfoDistri> util = new ExcelUtil<>(JcIteminfoDistri.class);
        List<JcIteminfoDistri> distriList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = jcIteminfoDistriService.imporIteminfoDistri(distriList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<JcIteminfoDistri> util = new ExcelUtil<>(JcIteminfoDistri.class);
        util.importTemplateExcel(response, "物料储分配送工艺基础表数据");
    }

    /**
     * 获取物料储分配送工艺基础表详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:iteminfoDistri:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(jcIteminfoDistriService.selectJcIteminfoDistriById(id));
    }

    /**
     * 新增物料储分配送工艺基础表
     */
    @PreAuthorize("@ss.hasPermi('base:iteminfoDistri:add')")
    @Log(title = "物料储分配送工艺基础表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcIteminfoDistri jcIteminfoDistri)
    {
        return toAjax(jcIteminfoDistriService.insertJcIteminfoDistri(jcIteminfoDistri));
    }

    /**
     * 修改物料储分配送工艺基础表
     */
    @PreAuthorize("@ss.hasPermi('base:iteminfoDistri:edit')")
    @Log(title = "物料储分配送工艺基础表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcIteminfoDistri jcIteminfoDistri)
    {
        return toAjax(jcIteminfoDistriService.updateJcIteminfoDistri(jcIteminfoDistri));
    }

    /**
     * 删除物料储分配送工艺基础表
     */
    @PreAuthorize("@ss.hasPermi('base:iteminfoDistri:remove')")
    @Log(title = "物料储分配送工艺基础表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcIteminfoDistriService.deleteJcIteminfoDistriByIds(ids));
    }
}
